defmodule ProgContestWeb.Token do
  @endpoint ProgContestWeb.Endpoint
  @secret_key_base Application.fetch_env!(:prog_contest, @endpoint) |> Keyword.fetch!(:secret_key_base)

  @spec sign(any) :: binary
  def sign(data) do
    Phoenix.Token.sign(@endpoint, @secret_key_base, data)
  end

  @spec verify(nil | binary, any) :: {:error, :expired | :invalid | :missing} | {:ok, any}
  def verify(token, opts \\ []) do
    Phoenix.Token.verify(@endpoint, @secret_key_base, token, opts)
  end
end
